﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using ProjetCom.Ctrl;
using ProjetCom.Model.CasseBriques;
using ProjetCom.Model.Template;

namespace ProjetCom.Vue
{
    class LevelBriques : Level
    {
        // Texture
        private Dictionary<string, Texture2D> m_BlockSheets;

        public LevelBriques(IServiceProvider p_serviceProvider, CtrlTemplate p_ctrl)
            : base(p_serviceProvider, p_ctrl)
        {
            // load the textures
            m_BlockSheets = new Dictionary<string, Texture2D>();
            m_BlockSheets.Add("Brique1", Content.Load<Texture2D>("Sprites/Briques/brique1"));
            m_BlockSheets.Add("Brique2", Content.Load<Texture2D>("Sprites/Briques/brique2"));
            m_BlockSheets.Add("Balle", Content.Load<Texture2D>("Sprites/Briques/balle"));
            m_BlockSheets.Add("Barre", Content.Load<Texture2D>("Sprites/Briques/barre"));

            ColorBackground = Color.Black;
        }

        public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch p_spriteBatch)
        {
            foreach (Element element in ((CtrlBriques)m_Ctrl).Elements)
            {
                if (element.IsAlive)
                    p_spriteBatch.Draw(m_BlockSheets[element.Name], element.Rectangle, Color.White);
            }


            foreach (Element element in ((CtrlBriques)m_Ctrl).Elements)
            {
                if (element.IsAlive)
                    p_spriteBatch.Draw(m_BlockSheets[element.Name], element.Rectangle, Color.White);
            }

            DrawScore(p_spriteBatch);
            DrawLife(p_spriteBatch);
        }

        public override void Dispose()
        {
        }


        protected void DrawLife(SpriteBatch p_spriteBatch)
        {
            SpriteFont font = Content.Load<SpriteFont>("SpriteFont/SpriteFont");
            string strLife = "Vie : " + ((CtrlBriques)m_Ctrl).Life.ToString();

            p_spriteBatch.DrawString(font, strLife, new Vector2(1170, 0), Color.White);
        }
    }
}
